import axios from 'axios';
import store from '../../store';

const isDev = process.env.NODE_ENV === 'development';

// 仅适用于本地开发时 存在一个本地代理的地址 如果代理多个地址 需要改动
// debugger;
const service = axios.create({
  timeout: 1000 * 30,
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
  },
  baseURL: process.env.NODE_ENV === 'development' ? '/api' : process.env.VUE_APP_REQUEST_BASE_URL
});

service.interceptors.request.use(
  config => {
    config.headers.Authorization =
      'bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZXF1ZXN0X3BhcmFtZXRlcnMiOnsiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIn0sInR5cCI6InVzZXIiLCJ0ZW5hbnRfaWQiOjM0Njk0NjI0OTA5MTU0MzA0MCwiY2xpZW50X2lkIjoicWN5eF9tZSIsInNjaG9vbF9pZCI6MzQ2OTQ2MjQ5MTE2NzA4ODY1LCJleHAiOjIwMTY2ODYwNDcsInNjb3BlIjpbIklERU5UWV80Il19.WKRMXxTX621UnuiBDx4XvC3cUSNR_9geg_-9CwR7saQ';
    // 'bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZXF1ZXN0X3BhcmFtZXRlcnMiOnsiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIn0sInR5cCI6InVzZXIiLCJ0ZW5hbnRfaWQiOjMwMjAzMzQzODgzNDQ4NzMxMywiY2xpZW50X2lkIjoicWN5eF9tZSIsInNjaG9vbF9pZCI6MjIxOTU0ODM4MTczMzIzMjY0LCJleHAiOjIwMTY2Njc3MTksInNjb3BlIjpbIklERU5UWV80Il19.mo1xTV4Vpl-gO_kf3EVxYo_wDA02Wvv96a_b53jEkkk';
    return config;
  },
  error => {
    console.log(error);
    return Promise.reject(error);
  }
);

service.interceptors.response.use(
  res => {
    return res;
  },
  error => {
    return Promise.reject(error.response);
  }
);

export default service;
